<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>管理学生成绩</h2>

<label>按条件查询:</label>
<label>科目:<select class="subjcetselect">
<option selected="selected"></option>
<c:forEach items="${subjectList }" var="subjectVO">
<option value="${subjectVO.id }">${subjectVO.name }</option>
</c:forEach>
</select></label>
<label>学号:<input type="text" class="studentId" /></label>
<label>姓名:<input type="text" class="studentName" /></label>
<label>考试日期:<input type="date" class = "testDate"/></label>

<button class="ui-pg-button ui-corner-all" title="" id="searchScore" data-original-title="Find records"><div class="ui-pg-div"><span class="ui-icon ace-icon fa fa-search orange"></span></div></button>


<div class="modal fade" id="editScoreModal" tabindex="-1" role="dialog" aria-labelledby="editTestModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
						</button>
						<h4 class="model-title" id="addTestModalLabel">
							更改成绩
						</h4>
					</div>
					<div class="modal-body">
						<form id="editTestForm" method="POST">
						<label>成绩编号:&nbsp;&nbsp;</label><span class="score-id"></span><br/>
						<label>学号:&nbsp;&nbsp;</label><span class="student-id"></span><br/>
						<label>姓名:&nbsp;&nbsp;</label><span class="student-name"></span><br/>
						<label>科目:&nbsp;&nbsp;</label><span class="subject-name"></span><br/>
						<label>考试日期:&nbsp;&nbsp;</label><span class="test-date"></span><br/>
						<label>成绩:&nbsp;&nbsp;</label><input type="text" class="test_score"/><br/>
						</form>
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-default saveEditScoreBtn" data-dismiss="modal">更改</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
					
				</div>
			</div>
		
		</div>

<table class="table table-striped table-bordered table-hover  no-footer scoretable">
												<thead>
													<tr role="row">
													<th class="sorting " tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Domain: activate to sort column ascending">成绩序号</th>
													<th class="sorting " tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Domain: activate to sort column ascending">科目</th>
													<th class="sorting_asc" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Price: activate to sort column ascending" aria-sort="ascending">学号</th><th class="hidden-480 sorting" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Clicks: activate to sort column ascending">姓名</th><th class="sorting" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="
															
															Update
														: activate to sort column ascending">
															<i class="ace-icon fa fa-clock-o bigger-110 hidden-480"></i>
															考试日期
														</th><th class="hidden-480 sorting" tabindex="0" aria-controls="sample-table-2" rowspan="1" colspan="1" aria-label="Status: activate to sort column ascending">考试成绩</th><th class="sorting_disabled" rowspan="1" colspan="1" aria-label=""></th></tr>
												</thead>

												<tbody class="scoremessagebody">
												<c:forEach items="${scorevoList }" var="scorevo">
												<tr role="row" class="odd scoremessage">
														<td>${scorevo.id }
														</td>
														<td>
															${scorevo.subjectName }
														</td>
														<td class="sorting_1">${scorevo.studentId }</td>
														<td class="hidden-480">${scorevo.studentName }</td>
														<td>${scorevo.testDate }</td>

														<td class="hidden-480">
															${scorevo.testScore }
														</td>

														<td>
															<div class="hidden-sm hidden-xs action-buttons">
																
																
																<a class="green editScore" title="更改考试成绩">
																	<i class="ace-icon fa fa-pencil bigger-130"></i>
																</a>

																<a class="red deleteScore" title="删除考试记录" >
																	<i class="ace-icon fa fa-trash-o bigger-130"></i>
																</a>
															</div>
														</td>
													</tr>
													</c:forEach>
													</tbody>
											</table>
<script type="text/javascript">
	$("#searchScore").click(function(){
		var subjectId = $(".subjcetselect").val();
		var studentId = $(".studentId").val();
		var studentName = $(".studentName").val();
		var testDate = $(".testDate").val();

		$.ajax({
			type:'POST',
			url:'searchScore',
			data:{
				subjectId:subjectId,
				studentId:studentId,
				studentName:studentName,
				testDate:testDate,
				},
				dataType:"json",
				success:function(data){
					$(".scoremessagebody").children("tr").remove();
					for(var i = 0;i<data.length;i++){
						var action = "<tr role='row' class='odd scoremessage'><td>"+data[i].id+"</td><td>"+data[i].subjectName+"</td><td class='sorting_1'>"+data[i].studentId+"</td><td class='hidden-480'>"+data[i].studentName+"</td><td>"+data[i].testDate+"</td><td class='hidden-480'>"+data[i].testScore+"</td><td><div class='hidden-sm hidden-xs action-buttons'><a class='green editScore' title='更改考试成绩'><i class='ace-icon fa fa-pencil bigger-130'></i></a><a class='red deleteScore' title='删除考试记录' ><i class='ace-icon fa fa-trash-o bigger-130'></i></a></div></td></tr>";
						$(".scoremessagebody").append(action);
						}
					$(".deleteScore").on("click",function(){
						deleteScorefunction($(this));
						});
					$(".editScore").on("click",function(){
						editScorefunction($(this));
						});
				},
				error:function(data, status, e){
					alert("系统繁忙"+e);
					}
			});
		});

	$(".editScore").click(function(){
		editScorefunction($(this));
		});
	function editScorefunction(a){
		var Id = a.parent().parent().siblings().eq(0).text();
		$.ajax({
			type:'POST',
			url:'showEditScore',
			data:{
				id:Id,
				},
				dataType:"json",
				success:function(data){
					$("#editScoreModal .score-id").text(Id);
					$("#editScoreModal .student-id").text(data.studentId);
					$("#editScoreModal .student-name").text(data.studentName);
					$("#editScoreModal .subject-name").text(data.subjectName);
					$("#editScoreModal .test-date").text(data.testDate);
					$("#editScoreModal .test_score").val(data.testScore);
					$("#editScoreModal").modal("show");
				},
				error:function(data, status, e){
					alert("系统繁忙"+e);
					}
			});
		}

	
	$(".saveEditScoreBtn").click(function(){
		var scoreId = $("#editScoreModal .score-id").text();
		var testScore = $("#editScoreModal .test_score").val();
		$.ajax({
			type:'POST',
			url:'saveEditScore',
			data:{
				id:scoreId,
				testScore:testScore,
				},
				dataType:"json",
				success:function(data){
					if(data.success){
						alert("更改成功!");
						window.location.reload();
						}
				},
				error:function(data, status, e){
					alert("系统繁忙"+e);
					}
			});
		});

	function deleteScorefunction(a){
		var Id = a.parent().parent().siblings().eq(0).text();
		if(confirm("是否确认删除")){
			$.ajax({
				type:'POST',
				url:'deleteScore',
				data:{
					id:Id,
					},
					dataType:"json",
					success:function(data){
						if(data.success){
							alert("删除成功!");
							window.location.reload();
							}
					},
					error:function(data, status, e){
						alert("系统繁忙"+e);
						}
				});
			}
		}
	$(".deleteScore").click(function(){
		deleteScorefunction($(this));
		});
</script>
</body>
</html>